/*************************************************
 *FileName:      withdrawalspsd.js
 *Description:   设置提现密码.js
 *Others:        陈灿
 *************************************************/
    /*
     * 启动
     */
    mui.init();
    mui('.mui-scroll-wrapper').scroll({
        indicators: false,      //是否显示滚动条 默认为true
        deceleration: 0.003,    //阻尼系数,系数越小滑动越灵敏 默认0.0006
        bounce: true,           //是否启用回弹 默认true
        longtap: true,          //默认为false
    });
    /*
     * 变量初始化
     */
    var uid = localStorage.replace_uid;
    var token = localStorage.replace_token
    var code_mobile = '';
    //发送手机验证码
    $('.getcode').on('tap',function(){
        var mobile = $("input[name='mobile']").val();
        code_mobile = mobile;
        if(mobile == '') {
            $("input[name='mobile']").attr("placeholder", "请输入手机号！");
            return false
        }
        if(mobile == '' || !/^1[3456789]\d{9}$/.test(mobile)) {
            mui.toast('请输入正确的手机号码',{duration:2000,type:'div'});
            return;
        }
        var btnID = this;
        var times = 60;
        btnID.setAttribute("disabled","disabled");
        btnID.innerHTML = times+"s后重新发送";
        var outtime = setInterval(function(){
            times--;
            btnID.innerHTML = times+"s后重新发送";
            if(times<=0){
                clearInterval(outtime);
                btnID.innerHTML = "发送验证码";
                btnID.removeAttribute("disabled");
            }
        },1000);
        $.ajax({
            type: "post",
            url: DOMAIN_NAME + "/index.php/api/code/payPasswordCode",
            dataType:'jsonp',
            data: { uid:uid,token:token,mobile: mobile },
            success: function(data) {
                if(data.error_code==0){
                    localStorage.replace_reset_code = data.code;
                }else if(data.error_code==1){
                    mui.toast(data.error_msg)
                    clearInterval(outtime);
                    btnID.innerHTML = "发送验证码";
                    btnID.removeAttribute("disabled");
                }
                console.log(data);
            }
        });
    })
    /**
     * 
     * 提交
     * @cc 
     * @DateTime 2018-01-08T06:19:16+0800
     * @param    int        
     * @return   void
     */
    $('.rdntn').on('tap',function(){
            var mobile = $("input[name='mobile']").val();
            var code = $("input[name='code']").val();
            var psw = $("input[name='psw']").val();
            var psws = $("input[name='psws']").val();
            var codes = localStorage.replace_reset_code;
            if(code == '') {
                mui.toast('请输入验证码！',{ duration:2000, type:'div' });
                return false
            }else if(psw != psws) {
                mui.toast('两次密码不一致！',{ duration:2000, type:'div' });
                return false
            }else if(!codes){
                mui.toast('请先获取验证码！',{ duration:2000, type:'div' });
                return false
            }else if(mobile != code_mobile) {
                $("input[name='mobile']").val('');
                mui.toast('手机号码必须填写获取验证码的号码！',{ duration:2000, type:'div' });
                return false
            }else{
                $.ajax({
                    type: "post",
                    url: DOMAIN_NAME + "/index.php/api/user/payPasswordSet",
                    dataType:'jsonp',
                    data: { uid:uid,token:token, code: code, codes: codes, withdraw_password: psw ,},
                    success: function(data) {
                        if(data.error_code == 0) {
                            localStorage.removeItem('replace_reset_code');
                            localStorage.replace_reset_mobile = mobile;
                            mui.toast('设置成功！',{ duration:2000, type:'div' });
                            setTimeout(function(){mui.back()},500);
                        }else{
                            mui.toast(data.error_msg,{ duration:2000, type:'div' });
                        }
                    }
                });
            }
                
        })